/*
 * acm1666.c
 *
 *  Created on: 11 Apr 2010
 *      Author: xuxu
 */

#include<stdio.h>
int coin[17]={1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289};
int con;
int n;

int finder(int node,int num)
{
	int i;
	if(num==n)
	{
		con++;
		return ;
	}
	for(i=node;i>=0;i--)
	{
		if(num+coin[i]<=n)
		{
			finder(i,num+coin[i]);
		}
	}
}

int main()
{
	int i;
	while(scanf("%d",&n)&&n)
	{
		i=0;
		while(coin[i++]<n)
			;
		i--;
		con=0;
		finder(i,0);
		printf("%d\n",con);
	}
	return 0;
}
